package wzc.design_pattern.construction.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author 那和不是个啥
 * @Date 2025/7/20
 * @Description 享元工厂（确保对象被复用）
 */

public class CircleFactory {
    private static final Map<String, Circle> circleMap = new HashMap<String, Circle>();

    public static Circle getCircle(String color) {
        Circle circle = circleMap.get(color);
        // 如果不存在该颜色的对象，则创建并存入缓存
        if (circle == null) {
            circle = new Circle(color);
            circleMap.put(color, circle);
            System.out.println("创建新的园：颜色=" + color);
        }
        return circle;
    }
}
